﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq.Mapping;
using System.Text.RegularExpressions;
using System.Web.Mvc;

namespace Maverick.Domain.Entities
{
    [Table(Name = "Messages")]
    public class Message
    {
        [HiddenInput(DisplayValue = false)]
        [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
        public int MessageID { get; set; }
        [HiddenInput(DisplayValue = false)]
        [Column] public int ParentID { get; set; }
        [Required(ErrorMessage = "Title required.")]
        [Column] public string Title { get; set; }
        [DataType(DataType.Html)]
        [UIHint("HTML")]
        [Required(ErrorMessage = "Text required.")]
        [Column] public string Text { get; set; }
        [HiddenInput(DisplayValue = false)]
        [Column] public DateTime DateTime { get; set; }
        [Required(ErrorMessage = "Author required.")]
        [Column] public string Author { get; set; }

        [HiddenInput(DisplayValue = false)]
        public string TitleUrl
        {
            get
            {
                if (!String.IsNullOrEmpty(Title))
                {
                    string _titleUrl = new Regex("[^a-zA-Z0-9\\s]").Replace(Title, String.Empty).Replace(" ", "-").ToLower();
                    return _titleUrl;
                }

                return String.Empty;
            }
        }

        [HiddenInput(DisplayValue = false)]
        [Column] public int? CategoryID { get; set; }
    }
}
